﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Skynet.BusinessEntities;

namespace Skynet.BusinessLogic.DataAccess
{
    public  class KindADOFACRepository : IKindRepository
    {

        public void Add(Kind item)
        {
            throw new NotImplementedException();
        }

        public void Add(IEnumerable<Kind> items)
        {
            throw new NotImplementedException();
        }

        public void Update(Kind item)
        {
            throw new NotImplementedException();
        }

        public void Update(IEnumerable<Kind> items)
        {
            throw new NotImplementedException();
        }

        public void Delete(Kind item)
        {
            throw new NotImplementedException();
        }

        public void Delete(IEnumerable<Kind> items)
        {
            throw new NotImplementedException();
        }

        public Kind GetOne(object key)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<Kind> GetAll()
        {
            var result = new List<Kind>();  

            string prov =  System.Configuration.ConfigurationManager.ConnectionStrings["SkynetLibrary"].ProviderName;
            string str = System.Configuration.ConfigurationManager.ConnectionStrings["SkynetLibrary"].ConnectionString;
            var fac = System.Data.Common.DbProviderFactories.GetFactory(prov);
            var con = fac.CreateConnection();
            con.ConnectionString = str;
            var cmd = con.CreateCommand();
            cmd.CommandText = "select * from  kinds";
            cmd.CommandType = System.Data.CommandType.Text;
            con.Open();
            var reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                var item = new Kind();
                result.Add(item); 
            }
            reader.Close();
            con.Close();
            return result;            
        }


        public Kind GetByTitle(string Title)
        {
            throw new NotImplementedException();
        }
    }
}
